package com.universest.swordholder.tools

import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.substring

fun TextFieldValue.getLineAtIndex(index:Int): TextRange {
    val lineStart = this.text.substring(0, index).lastIndexOf('\n') + 1
    return TextRange(lineStart, this.text.indexOf('\n', lineStart))
}
fun TextFieldValue.getStringLineAtIndex(index:Int): String {
    return this.text.substring(getLineAtIndex(index))
}

fun TextFieldValue.getStringBeforeSelection(): String{
    return this.text.substring(0, selection.start)
}

fun TextFieldValue.getStringAfterSelection(): String{
    return this.text.substring(selection.end)
}

fun TextFieldValue.getSelectedString(): String{
    return this.text.substring(selection)
}